<!-- 权限编辑 -->
<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal">
        <span aria-hidden="true">&times;</span><span class="sr-only">Close</span>
    </button>
    <h4 class="modal-title" id="mod-title">{$meta_title}</h4>
</div>
<div class="modal-body" id="content">
    <form class="form-horizontal m-t" id="signupForm">
        <input type="hidden" name="role_id" value="{$roleItem.role_id}">
        <div class="form-group">
            <label class="col-sm-3 control-label">角色名称:</label>
            <div class="col-sm-7">
                <label><input type="text" class="form-control" name="role_name" value="{$roleItem.role_name}"></label>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">描述:</label>
            <div class="col-sm-7">
                <label><input type="text" class="form-control" name="role_desc" value="{$roleItem.role_desc}"></label>
            </div>
        </div>
        <div class="" id="ibox-content">
            <div class="ibox-content timeline">
                {foreach $auth_list as $auth_root}
                {if($auth_root.pid == 0)}
                <div class="form-group">
                    <div class="col-sm-4 b-r">
                    <div class="checkbox i-checks">
                        <label><input type="checkbox" name="role_group" value="{$auth_root.id}" {if(in_array($auth_root.id,$roleItem.role_group))} checked {/if} > <i></i> {$auth_root.title}</label>
                    </div>
                    </div>
                    <div class="col-sm-7">
                        {foreach $auth_list as $auth_item}
                        {if($auth_root.id == $auth_item.pid)}
                        <div class="checkbox i-checks">
                            <label><input type="checkbox" name="role_group" value="{$auth_item.id}" {if(in_array($auth_item.id,$roleItem.role_group))} checked {/if}> <i></i> {$auth_item.title}</label>
                        </div>
                        {/if}
                        {/foreach}
                    </div>
                </div>
                <div class="hr-line-dashed"></div>
                {/if}
                {/foreach}
            </div>

        </div>
    </form>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-white" data-dismiss="modal">取消</button>
    <button type="button" class="btn btn-primary btn_save" data-dismiss="modal">快捷保存</button>
</div>

<script type="text/javascript">
    $(document).ready(function(){
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green',
            radioClass: 'iradio_square-green',
        });
        $('.i-checks').css("float","left");

        $(".btn_save").bind("click",function(){
            var role_id = $('input[name=role_id]').val();
            var role_name = $('input[name=role_name]').val();
            var role_desc = $('input[name=role_desc]').val();
            var role_group = {};
            var index = 0;
            $("input[name='role_group']").each(function () {
                if($(this).prop("checked")){
                    role_group[index] = $(this).val();
                    index++;
                }
            });
            var params = {
                role_id:role_id,
                role_name:role_name,
                role_desc:role_desc,
                role_group:JSON.stringify(role_group)
        }
            //  save
            $.ajax({
                url     :   "{:url('AdminRole/editRole')}",
                dataType:   "json",
                type    :   "post",
                data    :   params,
                success :   function( obj ){
                    layer.msg(obj.msg,{
                        shift   :   3
                    },function(){
                        if( obj.code === 1){
                            $('#role_list').bootstrapTable('refresh', null);
                        }
                    });
                }
            });
        });

    });
</script>